'use strict'

const { Type, Op } = require('../model');

async function getAll(ctx, next) {
    
        ctx.body = await Type.findAll();
 

}
async function getById(ctx, next) {
    let id = ctx.request.params.id;
    let data = await Role.findByPk(id);

    ctx.body = {
        code: 1000,
        data: data,
        msg: '查询指定项目成功'
    }
}
async function addItem(ctx, next) {
    let obj = ctx.request.body;
    let res = await Role.create({
        headline: obj.headline,
        email: obj.email,
        abstract:obj.abstract,
        content:obj.content,
        author:obj.author,
        time:obj.time
    })
    ctx.body = {
        code: 1000,
        data: null,
        msg: '新增成功'
    }
}
async function updateItem(ctx, next) {
    let id = ctx.request.params.id;
    let obj = ctx.request.body;
    await Role.update({ headline: obj.headline, email: obj.email,abstract:obj.abstract,content:obj.content,author:obj.author,time:obj.time }, {
        where: {
            id: id
        }
    });

    ctx.body = {
        code: 1000,
        data: null,
        msg: '修改成功'
    }
}
async function delItem(ctx, next) {
    let id = ctx.request.params.id;
    await Role.destroy({
        where: {
            id: id
        }
    });
    ctx.body = {
        code: 1000,
        data: null,
        msg: '删除成功'
    }
}
// async function getAll(ctx, next) {

// }

module.exports = {
    'get /types': getAll,
    'get /types/:id': getById,
    'post /types': addItem,
    'put /types/:id': updateItem,
    'del /types/:id': delItem,
}